package vn.aptech.leaveManagementSystem.view.general;

import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.JButton;

import sun.java2d.Disposer;
import vn.aptech.leaveManagementSystem.business.dto.Application;
import vn.aptech.leaveManagementSystem.business.model.MyModel;
import vn.aptech.leaveManagementSystem.business.parse.MyParse;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ViewApplicationForm extends JFrame{
	private JTextField txtfStartDate;
	private JTextField txtfEndDate;
	private int idAppParameter;
	private MyModel mymodel=new MyModel();
	private JTextArea txtaReason;
	private JTextArea txtaContact;
	private JButton btnClose;
	
	public ViewApplicationForm(int idApp) {
		idAppParameter=idApp;
		initGUI();
		initData();
		initAction();
	}

	private void initData() {
		getInfoApp();
	}

	private void initAction() {
		btnClose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Close();
			}
		});
	}

	/**
	 * Initialize the contents of the 
	 */
	private void initGUI() {
		setBounds(100, 100, 420, 285);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		getContentPane().setLayout(null);
		setLocationRelativeTo(null);
		
		JLabel lblStartDate = new JLabel("Start Date:");
		lblStartDate.setBounds(10, 11, 78, 14);
		getContentPane().add(lblStartDate);
		
		JLabel lblEndDate = new JLabel("End Date:");
		lblEndDate.setBounds(10, 36, 78, 14);
		getContentPane().add(lblEndDate);
		
		JLabel lblReason = new JLabel("Reason:");
		lblReason.setBounds(10, 64, 78, 14);
		getContentPane().add(lblReason);
		
		JLabel lblContact = new JLabel("Contact:");
		lblContact.setBounds(10, 146, 78, 14);
		getContentPane().add(lblContact);
		
		txtfStartDate = new JTextField();
		txtfStartDate.setBounds(98, 8, 282, 20);
		getContentPane().add(txtfStartDate);
		txtfStartDate.setColumns(10);
		
		txtfEndDate = new JTextField();
		txtfEndDate.setColumns(10);
		txtfEndDate.setBounds(98, 33, 282, 20);
		getContentPane().add(txtfEndDate);
		
		txtaReason = new JTextArea();
		txtaReason.setBounds(98, 59, 282, 79);
		getContentPane().add(txtaReason);
		
		txtaContact = new JTextArea();
		txtaContact.setBounds(98, 141, 282, 56);
		getContentPane().add(txtaContact);
		
		btnClose = new JButton("Close");
		btnClose.setIcon(new ImageIcon("icons/gif/16x16/Cancel.gif"));
		btnClose.setBounds(163, 208, 101, 23);
		getContentPane().add(btnClose);
	}
	
	public void getInfoApp()
	{
		try {
			ResultSet rs=mymodel.applications.getApplication(idAppParameter);
			if (rs.next())
			{
				Application tempApp=MyParse.toApplication(rs);
				txtfStartDate.setText(tempApp.getStartDate().toString());
				txtfEndDate.setText(tempApp.getEndDate().toString());
				txtaReason.setText(tempApp.getReason());
				txtaContact.setText(tempApp.getContact());
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void Close()
	{
		toBack();
		dispose();
	}
}
